source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-282.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.976.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1627 3125 6753 2025 885 387 4459 3508 3970 2974 1309 2524 3877 7108 6928 6432
17 18 19 20 21 22 23 24 25
2471 3523 4609 1929 6026 5324 2105 4148 6855
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt precip longitud latitud altitud
[1,] 0.07463533 -0.2033165 -0.4594562 -0.6123694 0.5253818
[2,] 0.13728853 -0.3722908 -0.5541218 -0.1800179 -0.5396723
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud latitud precip fecha_cnt altitud
0.9578747 0.9338975 0.8935537 0.8816973 0.8200988
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 46.00 Min. :0
1st Qu.: 2.000 1st Qu.:125.0 1st Qu.: 57.00 1st Qu.: 64.00 1st Qu.:0
Median : 5.000 Median :148.0 Median : 77.00 Median : 75.00 Median :0
Mean : 6.315 Mean :154.3 Mean : 82.09 Mean : 83.25 Mean :0
3rd Qu.:11.000 3rd Qu.:178.0 3rd Qu.:105.00 3rd Qu.: 93.00 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.86 1st Qu.: -8.411 1st Qu.: 32.0
Median : 0.0000 Median :42.89 Median : -4.846 Median : 98.0
Mean : 0.3816 Mean :41.82 Mean : -4.681 Mean : 196.6
3rd Qu.: 0.0000 3rd Qu.:43.35 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 4.216 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.0 Min. : 0.00
1st Qu.: 4.000 1st Qu.:148.0 1st Qu.: 50.0 1st Qu.: 3.00
Median : 7.000 Median :196.0 Median : 94.0 Median : 10.00
Mean : 6.503 Mean :200.6 Mean : 95.3 Mean : 14.39
3rd Qu.: 9.000 3rd Qu.:257.0 3rd Qu.: 143.0 3rd Qu.: 21.00
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :126.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.95 1st Qu.: -4.8500
Median :0.000000 Median : 0.0000 Median :40.95 Median : -2.4831
Mean :0.000331 Mean : 0.5056 Mean :40.49 Mean : -2.3654
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.5356
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 261.0
Mean : 419.5
3rd Qu.: 667.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 30.0 Min. :-31.0 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.00 Median :0
Mean : 6.505 Mean :217.7 Mean :150.9 Mean : 6.74 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.00 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.56 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03093 Mean :28.37 Mean :-16.05 Mean : 514.5
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 46.00 Min. :0
1st Qu.: 2.000 1st Qu.:125.0 1st Qu.: 57.00 1st Qu.: 64.00 1st Qu.:0
Median : 5.000 Median :148.0 Median : 77.00 Median : 75.00 Median :0
Mean : 6.315 Mean :154.3 Mean : 82.09 Mean : 83.25 Mean :0
3rd Qu.:11.000 3rd Qu.:178.0 3rd Qu.:105.00 3rd Qu.: 93.00 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.86 1st Qu.: -8.411 1st Qu.: 32.0
Median : 0.0000 Median :42.89 Median : -4.846 Median : 98.0
Mean : 0.3816 Mean :41.82 Mean : -4.681 Mean : 196.6
3rd Qu.: 0.0000 3rd Qu.:43.35 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 4.216 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 4.0 1st Qu.:152.0 1st Qu.: 53.00 1st Qu.: 3.00
Median : 7.0 Median :199.0 Median : 97.00 Median :10.00
Mean : 6.5 Mean :204.5 Mean : 98.04 Mean :13.69
3rd Qu.: 9.0 3rd Qu.:260.0 3rd Qu.: 145.00 3rd Qu.:20.00
Max. :12.0 Max. :403.0 Max. : 254.00 Max. :67.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-4.8500
Median :0.000000 Median : 0.00000 Median :40.95 Median :-2.4831
Mean :0.000342 Mean : 0.04738 Mean :40.44 Mean :-2.4379
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 0.4914
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 247.0
Mean : 359.7
3rd Qu.: 639.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.0
1st Qu.: 4.000 1st Qu.: 33.00 1st Qu.: -29.75 1st Qu.: 16.0
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.5
Mean : 6.586 Mean : 89.72 Mean : 18.43 Mean : 34.0
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 47.0
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :126.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 13.38 Mean :41.86 Mean : -0.3277
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2143
Mean :2100
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 30.0 Min. :-31.0 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.00 Median :0
Mean : 6.505 Mean :217.7 Mean :150.9 Mean : 6.74 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.00 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.56 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03093 Mean :28.37 Mean :-16.05 Mean : 514.5
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 46.00 Min. :0
1st Qu.: 2.000 1st Qu.:125.0 1st Qu.: 57.00 1st Qu.: 64.00 1st Qu.:0
Median : 5.000 Median :148.0 Median : 77.00 Median : 75.00 Median :0
Mean : 6.315 Mean :154.3 Mean : 82.09 Mean : 83.25 Mean :0
3rd Qu.:11.000 3rd Qu.:178.0 3rd Qu.:105.00 3rd Qu.: 93.00 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.86 1st Qu.: -8.411 1st Qu.: 32.0
Median : 0.0000 Median :42.89 Median : -4.846 Median : 98.0
Mean : 0.3816 Mean :41.82 Mean : -4.681 Mean : 196.6
3rd Qu.: 0.0000 3rd Qu.:43.35 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 4.216 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:150.0 1st Qu.: 48.00 1st Qu.: 3.00
Median : 4.000 Median :189.0 Median : 88.00 Median :10.00
Mean : 4.748 Mean :198.9 Mean : 90.57 Mean :13.18
3rd Qu.: 7.000 3rd Qu.:246.0 3rd Qu.:134.00 3rd Qu.:20.00
Max. :12.000 Max. :403.0 Max. :250.00 Max. :66.00
nevada prof_nieve longitud latitud
Min. :0.00000 Min. : 0.00000 Min. :35.28 Min. :-8.649
1st Qu.:0.00000 1st Qu.: 0.00000 1st Qu.:37.84 1st Qu.:-5.649
Median :0.00000 Median : 0.00000 Median :40.66 Median :-3.789
Mean :0.00038 Mean : 0.06007 Mean :40.12 Mean :-3.398
3rd Qu.:0.00000 3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.:-1.411
Max. :6.00000 Max. :75.00000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 200.0
Mean : 363.1
3rd Qu.: 656.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.0
1st Qu.: 4.000 1st Qu.: 33.00 1st Qu.: -29.75 1st Qu.: 16.0
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.5
Mean : 6.586 Mean : 89.72 Mean : 18.43 Mean : 34.0
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 47.0
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :126.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 13.38 Mean :41.86 Mean : -0.3277
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2143
Mean :2100
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-110.0 Min. : 0.0
1st Qu.: 8.000 1st Qu.:156.0 1st Qu.: 63.0 1st Qu.: 3.0
Median :10.000 Median :221.0 Median : 112.0 Median :10.0
Mean : 9.252 Mean :213.4 Mean : 109.8 Mean :14.5
3rd Qu.:11.000 3rd Qu.:272.0 3rd Qu.: 159.0 3rd Qu.:21.0
Max. :12.000 Max. :386.0 Max. : 254.0 Max. :67.0
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :37.19 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:39.88 1st Qu.:-2.9056
Median :0.0000000 Median : 0.00000 Median :41.29 Median : 0.0406
Mean :0.0002829 Mean : 0.02744 Mean :40.96 Mean :-0.9290
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 1.1678
Max. :3.0000000 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.0
Mean : 354.4
3rd Qu.: 617.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 30.0 Min. :-31.0 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.00 Median :0
Mean : 6.505 Mean :217.7 Mean :150.9 Mean : 6.74 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.00 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.56 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03093 Mean :28.37 Mean :-16.05 Mean : 514.5
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 42.0 Min. :-42.00 Min. : 46.00 Min. :0
1st Qu.: 2.000 1st Qu.:126.0 1st Qu.: 57.00 1st Qu.: 63.00 1st Qu.:0
Median : 5.000 Median :149.0 Median : 77.00 Median : 72.00 Median :0
Mean : 6.194 Mean :155.6 Mean : 82.59 Mean : 74.77 Mean :0
3rd Qu.:11.000 3rd Qu.:179.0 3rd Qu.:105.00 3rd Qu.: 85.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :120.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:41.91 1st Qu.: -7.863 1st Qu.: 27.1
Median : 0.00000 Median :42.89 Median : -3.831 Median : 95.0
Mean : 0.08719 Mean :41.90 Mean : -4.454 Mean : 174.5
3rd Qu.: 0.00000 3rd Qu.:43.36 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1082.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:150.0 1st Qu.: 48.00 1st Qu.: 3.00
Median : 4.000 Median :189.0 Median : 88.00 Median :10.00
Mean : 4.748 Mean :198.9 Mean : 90.57 Mean :13.18
3rd Qu.: 7.000 3rd Qu.:246.0 3rd Qu.:134.00 3rd Qu.:20.00
Max. :12.000 Max. :403.0 Max. :250.00 Max. :66.00
nevada prof_nieve longitud latitud
Min. :0.00000 Min. : 0.00000 Min. :35.28 Min. :-8.649
1st Qu.:0.00000 1st Qu.: 0.00000 1st Qu.:37.84 1st Qu.:-5.649
Median :0.00000 Median : 0.00000 Median :40.66 Median :-3.789
Mean :0.00038 Mean : 0.06007 Mean :40.12 Mean :-3.398
3rd Qu.:0.00000 3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.:-1.411
Max. :6.00000 Max. :75.00000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 200.0
Mean : 363.1
3rd Qu.: 656.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.0
1st Qu.: 4.000 1st Qu.: 33.00 1st Qu.: -29.75 1st Qu.: 16.0
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.5
Mean : 6.586 Mean : 89.72 Mean : 18.43 Mean : 34.0
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 47.0
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :126.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 13.38 Mean :41.86 Mean : -0.3277
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2143
Mean :2100
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.0 Min. :109.0 Min. :0
1st Qu.: 2.000 1st Qu.:117.0 1st Qu.: 55.0 1st Qu.:124.0 1st Qu.:0
Median :10.000 Median :137.0 Median : 76.0 Median :136.0 Median :0
Mean : 7.235 Mean :143.9 Mean : 78.3 Mean :147.6 Mean :0
3rd Qu.:11.000 3rd Qu.:165.0 3rd Qu.:100.5 3rd Qu.:155.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.0 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 43.3
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 2.615 Mean :41.26 Mean : -6.406 Mean : 364.8
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.819 3rd Qu.: 370.0
Max. :607.000 Max. :43.57 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-110.0 Min. : 0.0
1st Qu.: 8.000 1st Qu.:156.0 1st Qu.: 63.0 1st Qu.: 3.0
Median :10.000 Median :221.0 Median : 112.0 Median :10.0
Mean : 9.252 Mean :213.4 Mean : 109.8 Mean :14.5
3rd Qu.:11.000 3rd Qu.:272.0 3rd Qu.: 159.0 3rd Qu.:21.0
Max. :12.000 Max. :386.0 Max. : 254.0 Max. :67.0
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :37.19 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:39.88 1st Qu.:-2.9056
Median :0.0000000 Median : 0.00000 Median :41.29 Median : 0.0406
Mean :0.0002829 Mean : 0.02744 Mean :40.96 Mean :-0.9290
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 1.1678
Max. :3.0000000 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.0
Mean : 354.4
3rd Qu.: 617.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 30.0 Min. :-31.0 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.00 Median :0
Mean : 6.505 Mean :217.7 Mean :150.9 Mean : 6.74 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.00 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.56 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03093 Mean :28.37 Mean :-16.05 Mean : 514.5
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 42.0 Min. :-42.00 Min. : 46.00 Min. :0
1st Qu.: 2.000 1st Qu.:126.0 1st Qu.: 57.00 1st Qu.: 63.00 1st Qu.:0
Median : 5.000 Median :149.0 Median : 77.00 Median : 72.00 Median :0
Mean : 6.194 Mean :155.6 Mean : 82.59 Mean : 74.77 Mean :0
3rd Qu.:11.000 3rd Qu.:179.0 3rd Qu.:105.00 3rd Qu.: 85.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :120.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:41.91 1st Qu.: -7.863 1st Qu.: 27.1
Median : 0.00000 Median :42.89 Median : -3.831 Median : 95.0
Mean : 0.08719 Mean :41.90 Mean : -4.454 Mean : 174.5
3rd Qu.: 0.00000 3rd Qu.:43.36 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1082.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : 29.0 Min. :-68.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:143.0 1st Qu.: 42.00 1st Qu.: 4.00
Median :3.000 Median :168.0 Median : 67.00 Median :11.00
Mean :2.782 Mean :167.8 Mean : 66.53 Mean :15.17
3rd Qu.:4.000 3rd Qu.:193.0 3rd Qu.: 90.00 3rd Qu.:24.00
Max. :7.000 Max. :352.0 Max. :206.00 Max. :66.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :36.83 Min. :-4.0233
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-0.5000
Median :0.000000 Median : 0.00000 Median :41.34 Median : 0.5950
Mean :0.000668 Mean : 0.04895 Mean :40.80 Mean : 0.5786
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 1.9356
Max. :4.000000 Max. :40.00000 Max. :43.49 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 29.0
Median : 85.0
Mean : 174.8
3rd Qu.: 263.0
Max. :1002.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:137.0 1st Qu.: 33.00 1st Qu.: 4.00
Median : 5.000 Median :190.0 Median : 82.00 Median :11.00
Mean : 4.759 Mean :196.6 Mean : 81.89 Mean :12.99
3rd Qu.: 7.000 3rd Qu.:255.0 3rd Qu.:131.00 3rd Qu.:19.00
Max. :12.000 Max. :400.0 Max. :250.00 Max. :64.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :37.13 Min. :-8.649
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:40.41 1st Qu.:-5.661
Median :0.000000 Median : 0.00000 Median :41.52 Median :-3.919
Mean :0.000436 Mean : 0.08891 Mean :41.40 Mean :-4.302
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.59 3rd Qu.:-3.174
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 2.438
altitud
Min. : 5.0
1st Qu.: 370.0
Median : 656.0
Mean : 594.4
3rd Qu.: 846.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.0
1st Qu.: 4.000 1st Qu.: 33.00 1st Qu.: -29.75 1st Qu.: 16.0
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.5
Mean : 6.586 Mean : 89.72 Mean : 18.43 Mean : 34.0
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 47.0
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :126.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 13.38 Mean :41.86 Mean : -0.3277
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2143
Mean :2100
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.0 Min. :109.0 Min. :0
1st Qu.: 2.000 1st Qu.:117.0 1st Qu.: 55.0 1st Qu.:124.0 1st Qu.:0
Median :10.000 Median :137.0 Median : 76.0 Median :136.0 Median :0
Mean : 7.235 Mean :143.9 Mean : 78.3 Mean :147.6 Mean :0
3rd Qu.:11.000 3rd Qu.:165.0 3rd Qu.:100.5 3rd Qu.:155.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.0 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 43.3
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 2.615 Mean :41.26 Mean : -6.406 Mean : 364.8
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.819 3rd Qu.: 370.0
Max. :607.000 Max. :43.57 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-110.0 Min. : 0.0
1st Qu.: 8.000 1st Qu.:156.0 1st Qu.: 63.0 1st Qu.: 3.0
Median :10.000 Median :221.0 Median : 112.0 Median :10.0
Mean : 9.252 Mean :213.4 Mean : 109.8 Mean :14.5
3rd Qu.:11.000 3rd Qu.:272.0 3rd Qu.: 159.0 3rd Qu.:21.0
Max. :12.000 Max. :386.0 Max. : 254.0 Max. :67.0
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :37.19 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:39.88 1st Qu.:-2.9056
Median :0.0000000 Median : 0.00000 Median :41.29 Median : 0.0406
Mean :0.0002829 Mean : 0.02744 Mean :40.96 Mean :-0.9290
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 1.1678
Max. :3.0000000 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.0
Mean : 354.4
3rd Qu.: 617.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 84.0 Min. :-17.0 Min. : 0.0 Min. :0
1st Qu.: 4.000 1st Qu.:180.0 1st Qu.: 91.0 1st Qu.: 0.0 1st Qu.:0
Median : 7.000 Median :224.0 Median :129.0 Median : 6.0 Median :0
Mean : 6.569 Mean :232.6 Mean :130.2 Mean :11.7 Mean :0
3rd Qu.: 9.000 3rd Qu.:280.0 3rd Qu.:174.0 3rd Qu.:19.0 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :246.0 Max. :63.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-6.9492 Min. : 1.00
1st Qu.: 0.0000 1st Qu.:36.50 1st Qu.:-6.3317 1st Qu.: 19.00
Median : 0.0000 Median :36.85 Median :-5.6000 Median : 32.00
Mean : 0.0136 Mean :36.95 Mean :-5.3403 Mean : 83.39
3rd Qu.: 0.0000 3rd Qu.:37.28 3rd Qu.:-4.8458 3rd Qu.: 90.00
Max. :34.0000 Max. :39.47 Max. : 0.8031 Max. :717.00
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 30.0 Min. :-31.0 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.00 Median :0
Mean : 6.505 Mean :217.7 Mean :150.9 Mean : 6.74 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.00 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.56 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03093 Mean :28.37 Mean :-16.05 Mean : 514.5
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 42.0 Min. :-42.00 Min. : 46.00 Min. :0
1st Qu.: 2.000 1st Qu.:126.0 1st Qu.: 57.00 1st Qu.: 63.00 1st Qu.:0
Median : 5.000 Median :149.0 Median : 77.00 Median : 72.00 Median :0
Mean : 6.194 Mean :155.6 Mean : 82.59 Mean : 74.77 Mean :0
3rd Qu.:11.000 3rd Qu.:179.0 3rd Qu.:105.00 3rd Qu.: 85.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :120.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:41.91 1st Qu.: -7.863 1st Qu.: 27.1
Median : 0.00000 Median :42.89 Median : -3.831 Median : 95.0
Mean : 0.08719 Mean :41.90 Mean : -4.454 Mean : 174.5
3rd Qu.: 0.00000 3rd Qu.:43.36 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1082.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : 29.0 Min. :-68.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:143.0 1st Qu.: 42.00 1st Qu.: 4.00
Median :3.000 Median :168.0 Median : 67.00 Median :11.00
Mean :2.782 Mean :167.8 Mean : 66.53 Mean :15.17
3rd Qu.:4.000 3rd Qu.:193.0 3rd Qu.: 90.00 3rd Qu.:24.00
Max. :7.000 Max. :352.0 Max. :206.00 Max. :66.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :36.83 Min. :-4.0233
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-0.5000
Median :0.000000 Median : 0.00000 Median :41.34 Median : 0.5950
Mean :0.000668 Mean : 0.04895 Mean :40.80 Mean : 0.5786
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 1.9356
Max. :4.000000 Max. :40.00000 Max. :43.49 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 29.0
Median : 85.0
Mean : 174.8
3rd Qu.: 263.0
Max. :1002.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:137.0 1st Qu.: 33.00 1st Qu.: 4.00
Median : 5.000 Median :190.0 Median : 82.00 Median :11.00
Mean : 4.759 Mean :196.6 Mean : 81.89 Mean :12.99
3rd Qu.: 7.000 3rd Qu.:255.0 3rd Qu.:131.00 3rd Qu.:19.00
Max. :12.000 Max. :400.0 Max. :250.00 Max. :64.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :37.13 Min. :-8.649
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:40.41 1st Qu.:-5.661
Median :0.000000 Median : 0.00000 Median :41.52 Median :-3.919
Mean :0.000436 Mean : 0.08891 Mean :41.40 Mean :-4.302
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.59 3rd Qu.:-3.174
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 2.438
altitud
Min. : 5.0
1st Qu.: 370.0
Median : 656.0
Mean : 594.4
3rd Qu.: 846.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.0
1st Qu.: 4.000 1st Qu.: 33.00 1st Qu.: -29.75 1st Qu.: 16.0
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.5
Mean : 6.586 Mean : 89.72 Mean : 18.43 Mean : 34.0
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 47.0
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :126.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 13.38 Mean :41.86 Mean : -0.3277
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2143
Mean :2100
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.0 Min. :109.0 Min. :0
1st Qu.: 2.000 1st Qu.:117.0 1st Qu.: 55.0 1st Qu.:124.0 1st Qu.:0
Median :10.000 Median :137.0 Median : 76.0 Median :136.0 Median :0
Mean : 7.235 Mean :143.9 Mean : 78.3 Mean :147.6 Mean :0
3rd Qu.:11.000 3rd Qu.:165.0 3rd Qu.:100.5 3rd Qu.:155.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.0 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 43.3
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 2.615 Mean :41.26 Mean : -6.406 Mean : 364.8
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.819 3rd Qu.: 370.0
Max. :607.000 Max. :43.57 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-38.0 Min. : 0.000
1st Qu.: 6.000 1st Qu.:205.0 1st Qu.:101.0 1st Qu.: 2.000
Median : 8.000 Median :257.0 Median :147.0 Median : 6.000
Mean : 8.262 Mean :244.7 Mean :137.8 Mean : 7.482
3rd Qu.:10.000 3rd Qu.:291.0 3rd Qu.:180.0 3rd Qu.:12.000
Max. :12.000 Max. :386.0 Max. :254.0 Max. :31.000
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :37.79 Min. :-3.8314
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.: 0.0406
Median :0.0000000 Median : 0.00000 Median :41.29 Median : 0.5950
Mean :0.0003547 Mean : 0.01312 Mean :40.66 Mean : 0.6103
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.68 3rd Qu.: 1.6331
Max. :3.0000000 Max. :59.00000 Max. :43.49 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 29.0
Median : 81.0
Mean : 177.4
3rd Qu.: 283.0
Max. :1097.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. : 6.00 Min. : 8.0 Min. :-110.00 Min. : 0.00
1st Qu.: 9.00 1st Qu.:124.0 1st Qu.: 37.00 1st Qu.: 8.00
Median :10.00 Median :176.0 Median : 78.00 Median :21.00
Mean :10.38 Mean :177.8 Mean : 77.92 Mean :22.47
3rd Qu.:11.00 3rd Qu.:228.0 3rd Qu.: 116.00 3rd Qu.:34.00
Max. :12.00 Max. :355.0 Max. : 244.00 Max. :67.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :37.19 Min. :-8.649
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:40.41 1st Qu.:-4.535
Median :0.0000000 Median : 0.0000 Median :41.29 Median :-3.450
Mean :0.0002014 Mean : 0.0437 Mean :41.29 Mean :-2.677
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.37 3rd Qu.:-1.293
Max. :2.0000000 Max. :35.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 251.0
Median : 617.0
Mean : 555.3
3rd Qu.: 790.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 7.000 Min. : 90.0 Min. :-10.0 Min. : 0.00 Min. :0
1st Qu.: 8.000 1st Qu.:197.0 1st Qu.:114.0 1st Qu.: 0.00 1st Qu.:0
Median : 9.000 Median :260.0 Median :162.0 Median : 3.00 Median :0
Mean : 9.435 Mean :255.3 Mean :150.6 Mean :10.07 Mean :0
3rd Qu.:11.000 3rd Qu.:307.0 3rd Qu.:191.0 3rd Qu.:16.00 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :246.0 Max. :61.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000000 Min. :35.28 Min. :-6.949 Min. : 1.00
1st Qu.: 0.000000 1st Qu.:36.50 1st Qu.:-6.332 1st Qu.: 19.00
Median : 0.000000 Median :36.85 Median :-5.600 Median : 34.00
Mean : 0.009942 Mean :36.97 Mean :-5.261 Mean : 88.21
3rd Qu.: 0.000000 3rd Qu.:37.28 3rd Qu.:-4.488 3rd Qu.: 90.00
Max. :26.000000 Max. :39.47 Max. :-1.169 Max. :582.00
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 84 Min. :-17.0 Min. : 0.0 Min. :0
1st Qu.:2.000 1st Qu.:170 1st Qu.: 79.0 1st Qu.: 2.0 1st Qu.:0
Median :4.000 Median :201 Median :108.0 Median :10.0 Median :0
Mean :3.572 Mean :209 Mean :108.9 Mean :13.4 Mean :0
3rd Qu.:5.000 3rd Qu.:240 3rd Qu.:140.0 3rd Qu.:21.0 3rd Qu.:0
Max. :6.000 Max. :379 Max. :216.0 Max. :63.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.9492 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:36.50 1st Qu.:-6.3317 1st Qu.: 19.00
Median : 0.00000 Median :36.83 Median :-5.6156 Median : 32.00
Mean : 0.01743 Mean :36.93 Mean :-5.4236 Mean : 78.36
3rd Qu.: 0.00000 3rd Qu.:37.28 3rd Qu.:-4.8458 3rd Qu.: 90.00
Max. :34.00000 Max. :39.47 Max. : 0.8031 Max. :717.00
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 30.0 Min. :-31.0 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.00 Median :0
Mean : 6.505 Mean :217.7 Mean :150.9 Mean : 6.74 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.00 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.56 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03093 Mean :28.37 Mean :-16.05 Mean : 514.5
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)